package judger

import "fmt"

type COMPILER int

type OJResult struct {
	ID         uint64
	Message    string
	Lang       COMPILER
	Compiler   STATE
	TestResult []TestResult
}
type TestCase struct {
	Stdin  string `json:"stdin"`
	Stdout string `json:"stdout"`
}
type TestResult struct {
	Status STATE
	Time   float64
	Memory float64
	Output string
}
type Question struct {
	ID          uint64     `json:"id"`
	Content     string     `json:"content"`
	Lang        uint64     `json:"lang"`
	LimitTime   uint64     `json:"limitTime"`
	LimitMemory uint64     `json:"limitMemory"`
	Testcase    []TestCase `json:"testcase"`
}

func (tc *TestCase) String() string {
	return "I:" + tc.Stdin + "\t O:" + tc.Stdout + "\t -_-\t"
}

func (this *OJResult) OJString() string {
	str := "Judged\t__ID:" + fmt.Sprintf("%d", this.ID) + "\t__LANG:" + this.Lang.String() + "\t__COMPILE:" + this.Compiler.String() + "__RESULT:" + this.Message + "\t__RESULT:["
	for i := 0; i < len(this.TestResult); i++ {
		str = str + this.TestResult[i].Status.String() + "|"
	}
	str = str + "]"
	return str
}

const (
	C_GCC = iota
	C_MINGW
	CPP_GPP
	CPP_MINGW
	JAVA_JAVAC_1_8
	JAVA_JAVAC_11
	PYTHON_CPYTHON
)

type STATE int

const (
	AFG_AC = iota + 100
	AFG_WA
	AFG_BG
	AFG_TO
	AFG_OM

	AFG_EC = -0x13
	AFG_IE = -0x12
	AFG_CE = -0x11
	AFG_CC = -0x10
)

func (this COMPILER) String() string {
	switch this {
	case C_GCC:
		return "C_GCC"
	case C_MINGW:
		return "C_MINGW"
	case CPP_GPP:
		return "CPP_GPP"
	case CPP_MINGW:
		return "CPP_MINGW"
	case JAVA_JAVAC_1_8:
		return "JAVA_JAVAC1.8"
	case JAVA_JAVAC_11:
		return "JAVA_JAVAC11"
	case PYTHON_CPYTHON:
		return "PYTHON_3"
	}
	return ""
}

func (this STATE) String() string {
	switch this {
	case AFG_IE:
		return "INTERNAL ERROR"
	case AFG_CC:
		return "COMPLETED"
	case AFG_CE:
		return "COMPILE ERROR"
	case AFG_AC:
		return "ALL COMPLETE"
	case AFG_WA:
		return "WRONG ANSWER"
	case AFG_BG:
		return "FORMAT ERROR"
	case AFG_EC:
		return "ERROR CALL"
	case AFG_TO:
		return "TIME OUT"
	case AFG_OM:
		return "OUT OF MEMORY"
	}

	return ""
}
